﻿using Aurora.HttpClient;
using Volo.Abp;
using Volo.Abp.Modularity;

namespace Gateway.UI.Api.AbpModules
{
    /// <summary>
    /// http client module
    /// </summary>
    [DependsOn()]
    public class HttpClientModule : AbpModule
    {
        /// <summary>
        /// configure service
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
        {
            var configuration = context.Services.GetConfiguration();
            context.Services.AddCoreHttpClient(opt =>
            {
                opt.UseDiscovery = false;
                opt.UsePolicy = false;
                opt.DiscoveryAction = (dis) =>
                {

                    // dis.UseConsulDiscovery(x =>
                    // {
                    //     builder.Configuration.GetSection("DiscoveryClient").Bind(x);
                    //     // x.ServiceRegisterSetting = new ServiceRegisterSetting();
                    //     // x.ServiceRegisterSetting = new ServiceRegisterSetting();
                    // });

                    // dis.UseNacosDiscovery(x =>
                    // {
                    //     configuration.GetSection("nacos").Bind(x);
                    //     // x.ServiceRegisterSetting = new ServiceRegisterSetting();
                    //     // x.ServiceRegisterSetting = new ServiceRegisterSetting();
                    // });
                };
            });
            return base.ConfigureServicesAsync(context);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
        {
            var app = context.GetApplicationBuilder();
            // app.UseDiscovery();
            return base.OnApplicationInitializationAsync(context);
        }
    }
}
